package com.woniu.secondhand.controller;

import com.woniu.common.annotation.LoginUser;
import com.woniu.common.entity.Result;
import com.woniu.secondhand.entity.vo.SellCollectVO;
import com.woniu.secondhand.pojo.SecondhandCollect;
import com.woniu.secondhand.service.ISecondhandCollectService;
import com.woniu.user.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author HMMT
 * @since 2023-05-20
 */
@RestController
@RequestMapping("/secondhandCollect")
@Api(tags = "收藏管理")
@Slf4j
public class SecondhandCollectController {
    @Autowired
    private ISecondhandCollectService collectService;

    @GetMapping("/sell")
    @ApiOperation("出售收藏查询")
    public Result<List<SellCollectVO>> searchSell(@LoginUser UserLoginVO userLoginVO) {
        List<SellCollectVO> sellCollectVOList = collectService.searchSell(userLoginVO);
        return Result.ok(sellCollectVOList);
    }

    @GetMapping("/want")
    @ApiOperation("求购收藏查询")
    public Result<List<SellCollectVO>> searchWant(@LoginUser UserLoginVO userLoginVO) {
        List<SellCollectVO> sellCollectVOList = collectService.searchWant(userLoginVO);
        return Result.ok(sellCollectVOList);
    }

    @PostMapping("/add/{id}")
    @ApiOperation("新增收藏")
    public Result<SecondhandCollect> add(@PathVariable Integer id, @LoginUser UserLoginVO userLoginVO) {
        SecondhandCollect collect = collectService.add(id, userLoginVO);
        return Result.ok(collect);
    }

    @DeleteMapping("/delete")
    @ApiOperation("批量删除收藏")
    public Result deletePart(@RequestBody List<Integer> ids) {
        Boolean flag = collectService.removeBatchByIds(ids);
        return Result.commonByFlag(flag);
    }
}
